﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using Chefbook.DataObjects;
using System.Globalization;
using Chefbook.DataAccessLayer;

namespace Chefbook.UserActions
{
    public class DeleteRecipeAction : UserActionBase
    {
        private Recipe recipeToDelete;
        private List<Category> categories;

        public DeleteRecipeAction(Recipe recipeToDelete)
        {
            this.recipeToDelete = recipeToDelete;
            this.categories = new List<Category>(recipeToDelete.Categories);
        }

        public override void DoAction()
        {
            base.DoAction();
            DatabaseConnector.DeleteObject(recipeToDelete);
        }

        public override void UndoAction()
        {
            base.UndoAction();
            categories.ForEach(category => category.AddRecipe(recipeToDelete));
        }

        public override string ToString()
        {
            return string.Format(CultureInfo.CurrentUICulture, "Delete Recipe '{0}'", recipeToDelete);
        }
    }
}
